﻿namespace Example
{
    using System.Linq;
    using System.Xml.Linq;
    using Xunit;

    public sealed class Linq2XmlFacts
    {
        [Fact]
        public void select_from_xml_where()
        {
            var xml = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XElement(
                    "root",
                    new XElement("child"),
                    new XElement(
                        "child",
                        new XAttribute("number", "123"))));

            var attributes = from element in xml.Descendants("child")
                             where null != element.Attribute("number")
                             select element.Attribute("number");

            var query = from attribute in attributes
                        where "123" == attribute.Value
                        select attribute;

            Assert.Equal(1, query.Count());
        }
    }
}